﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Twodi.Aspect.Interfaces;
using Microsoft.Xna.Framework;
using Twodi.Aspect.Implemented;
using Microsoft.Xna.Framework.Graphics;
using Twodi.Interfaces;

namespace Twodi.Implemented
{
    public class Textured : AbstractTextured
    {
        public Textured(Texture2D texture, Game game)
            : base(game)
        {
            this.TextureProperties = new TextureAspect(texture);
            SetDefinitions();
        }

        public Textured(String textureName, Game game)
            : base(game)
        {
            this.TextureProperties = new TextureAspect(textureName);
            SetDefinitions();            
        }

        private void SetDefinitions()
        {
            this.Size = new Vector2(this.Texture.Width, this.Texture.Height);

            this.TextureProperties.SourceChanged += (sender, e) =>
            {
                if (this.Source.HasValue)
                {
                    this.Size = new Vector2(Source.Value.Width, Source.Value.Height);
                }
            };
        }
    }
}
